package com.tham.dao;

import java.io.IOException;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import oracle.jdbc.OracleTypes;
import org.apache.log4j.Logger;
import com.tham.dto.ParametrosDTO;
import utiles.AppProperties;
import utiles.ConexionPool;


public class ParametrosThamDAO {
	private static Logger log = Logger.getLogger(ParametrosThamDAO.class);
	String pkgVar = (AppProperties.getProperty("aplicacion", "PACKAGE"));
	
	public  List<ParametrosDTO> getTipoPacAtencionByRUT(String rutPAC) throws SQLException, IOException{
		//ConexionPool connDao = new ConexionPool();
		Connection conn = ConexionPool.getConnectionPool();	
    	//Connection conn = ((javax.sql.PooledConnection)ConexionPool.getConnectionPool()).getConnection();
    			    
		List<ParametrosDTO> listParametros = new ArrayList<ParametrosDTO>();
		try {
			String query = "{ call "+pkgVar+".Pkg_tho_parametros.getTipoPacAtencionByRUT(?,?) }"; 	       
			CallableStatement  stmt = conn.prepareCall(query);
			stmt.setString(1, rutPAC);						
			stmt.registerOutParameter(2, OracleTypes.CURSOR);
			stmt.execute();
			ResultSet rs = (ResultSet)stmt.getObject(2);
			while (rs.next()) {
				ParametrosDTO paramDTO = new ParametrosDTO();				
				paramDTO.setTipoPacAte(rs.getString(1));
				paramDTO.setSocialSF(rs.getString(2));
				listParametros.add(paramDTO);				
			}
			rs.close();
			stmt.close();
		} catch (SQLException ex) {  
			log.error("Error ParametrosThamDAO.getTipoPacAtencionByRUT SQLException: " +ex.getMessage());
			System.out.println(ex.getMessage());
		} finally {
			//ConexionPool.desconectaPool(conn);
			conn.close();
			conn = null;
		}
		return listParametros;			
	}
	
	 public  List<ParametrosDTO> getHorasPACByProf(String idProf) throws SQLException, IOException{

			//ConexionPool connDao = new ConexionPool();
		 Connection conn = ConexionPool.getConnectionPool();	
	    	//Connection conn = ((javax.sql.PooledConnection)ConexionPool.getConnectionPool()).getConnection();
	    				    
			List<ParametrosDTO> listParametros = new ArrayList<ParametrosDTO>();
			try {
				String query = "{ call "+pkgVar+".Pkg_tho_parametros.getHorasPACByProf(?,?) }"; 	       
				CallableStatement  stmt = conn.prepareCall(query);
				stmt.setString(1, idProf);						
				stmt.registerOutParameter(2, OracleTypes.CURSOR);
				stmt.execute();
				ResultSet rs = (ResultSet)stmt.getObject(2);
				while (rs.next()) {
					ParametrosDTO paramDTO = new ParametrosDTO();				
					paramDTO.setHrsPacNuevo(rs.getString(1));
					paramDTO.setHrsPacControl(rs.getString(2));
					paramDTO.setHrsPacReevaluacion(rs.getString(3));
					listParametros.add(paramDTO);				
				}
				rs.close();
				stmt.close();
			} catch (SQLException ex) {  
				log.error("Error ParametrosThamDAO.getHorasPACByProf SQLException: " +ex.getMessage());
				System.out.println(ex.getMessage());
			} finally {
				//ConexionPool.desconectaPool(conn);
				conn.close();
				conn = null;
			}
			return listParametros;	
			
		} 
	 
	 

}
